package com.example.dorm1_demo.mapper;

import com.example.dorm1_demo.entity.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface StudentMapper {
    // 查询所有学生信息
    @Select("SELECT * FROM student")
    List<Student> selectAll();

    // 插入新的学生记录
    @Insert("INSERT INTO student(name, gender, age, className, major, phone, email, dormitoryId, dormitoryNumber) " +
            "VALUES(#{name}, #{gender}, #{age}, #{className}, #{major}, #{phone}, #{email}, #{dormitoryId}, #{dormitoryNumber})")
    int insert(Student student);

    // 更新学生信息
    @Update("UPDATE student SET name=#{name}, gender=#{gender}, age=#{age}, " +
            "className=#{className}, major=#{major}, phone=#{phone}, email=#{email}, " +
            "dormitoryId=#{dormitoryId}, dormitoryNumber=#{dormitoryNumber} WHERE id=#{id}")
    int update(Student student);

    // 删除指定ID的学生记录
    @Delete("DELETE FROM student WHERE id=#{id}")
    int delete(Integer id);

    // 根据ID查询学生信息
    @Select("SELECT * FROM student WHERE id=#{id}")
    Student selectById(Integer id);

    // 根据姓名查询学生信息
    @Select("SELECT * FROM student WHERE name LIKE CONCAT('%',#{name},'%')")
    List<Student> selectByName(String name);

    // 根据宿舍ID查询学生信息
    @Select("SELECT * FROM student WHERE dormitoryId=#{dormitoryId}")
    List<Student> selectByDormitoryId(Integer dormitoryId);
}